<?php
    $nuser = "";
    $nyear = "";
    $nmonth= "";
    $nday  = "";
    $nhour = "";
    $skn   = "";
    $msg   = "";
    $error = "";
    $cyear = "";
    $cmonth= "";
    $cday  = "";
    
    if (isset($_REQUEST['user_name']) && 
        isset($_REQUEST['year']) &&
        isset($_REQUEST['month']) &&
        isset($_REQUEST['day']) &&
        isset($_REQUEST['hour']) &&
        $_REQUEST['user_name'] != "" &&
        $_REQUEST['year'] != "" &&
        $_REQUEST['month'] != "" &&
        $_REQUEST['day'] != "" &&
        $_REQUEST['hour'] != "" ) 
    {
        global $db_manager;
        $nuser = $_REQUEST['user_name'];
        $nyear = $_REQUEST['year'];
        $nmonth= $_REQUEST['month'];
        $nday  = $_REQUEST['day'];
        $nhour = $_REQUEST['hour'];
        
        $xalta = new x_alta($db_manager);
        
        if ($xalta->is_valid_date($nday, $nmonth, $nyear)) {
        	
        	$date = sprintf("%s-%s-%s %s", $nyear, $nmonth, $nday, $nhour);
        	
            if ($xalta->add_alta($nuser, $date) > 0) {
                $msg = $labels["LBL_USR_ADDED"];
                $skn = "showmessage";           
	            // Log action
	            $xlog = new x_log($db_manager);
	            $xlog->add_msg(sprintf($log_msg["LOG_MSG_ADDUSR"], $nuser, $date));
            } else {
                $msg = $db_manager->db_error();
                $skn = "adduser";           
            }
        	
        } else {
            $msg = $labels["LBL_WRONG_DATE"];
            $skn = "adduser";
        }
    	    	
    } else {
    	$skn = "adduser";
    	$msg = "";
    }

    $Skinner=new Skinner();
    $Skinner->setSkin($skins_path.$skn);
    $Skinner->registerVariable("files_path", $files_path);
    $Skinner->registerVariable("admin_root", $admin_root);    
    $Skinner->registerVariable("message", $msg);
    $Skinner->registerVariable("lbl_add_usr", $labels["LBL_ADD_USR"]);
    $Skinner->registerVariable("lbl_username", $labels["LBL_USER"]);
    $Skinner->registerVariable("user_name_value", $nuser);
    $Skinner->registerVariable("lbl_expiredate", $labels["LBL_EXPIREDATE"]);
    /*
    $Skinner->registerVariable("lbl_january", $labels["LBL_JANUARY"]);
    $Skinner->registerVariable("lbl_february", $labels["LBL_FEBRUARY"]);
    $Skinner->registerVariable("lbl_march", $labels["LBL_MARCH"]);
    $Skinner->registerVariable("lbl_april", $labels["LBL_APRIL"]);
    $Skinner->registerVariable("lbl_may", $labels["LBL_MAY"]);
    $Skinner->registerVariable("lbl_june", $labels["LBL_JUNE"]);
    $Skinner->registerVariable("lbl_july", $labels["LBL_JULY"]);
    $Skinner->registerVariable("lbl_august", $labels["LBL_AUGUST"]);
    $Skinner->registerVariable("lbl_september", $labels["LBL_SEPTEMBER"]);
    $Skinner->registerVariable("lbl_october", $labels["LBL_OCTOBER"]);
    $Skinner->registerVariable("lbl_november", $labels["LBL_NOVEMBER"]);
    $Skinner->registerVariable("lbl_december", $labels["LBL_DECEMBER"]);
    */
    list($cyear, $cmonth, $cday) = split("-", date('Y-m-d'));
    for ($i=2010; $i<2015; $i++) {
    	$year_list = $year_list.sprintf(
    	    "<option value=\"%d\" %s>%d</option>\n", 
            $i, 
            ($i == $cyear ? "selected" : ""),
            $i);
    }
    
    for ($i=1; $i<=31; $i++) {
        $day_list = $day_list.sprintf(
    	    "<option value=\"%02d\" %s>%02d</option>\n",
    	    $i,
    	    ($i == $cday ? "selected" : ""),
    	    $i);
    }
    
    $month_name = array(
        $labels["LBL_JANUARY"],
        $labels["LBL_FEBRUARY"],
        $labels["LBL_MARCH"],
        $labels["LBL_APRIL"],
        $labels["LBL_MAY"],
        $labels["LBL_JUNE"],
        $labels["LBL_JULY"],
        $labels["LBL_AUGUST"],
        $labels["LBL_SEPTEMBER"],
        $labels["LBL_OCTOBER"],
        $labels["LBL_NOVEMBER"],
        $labels["LBL_DECEMBER"]
    );
    for ($i=1; $i <= 12; $i++) {
        $month_list = $month_list.sprintf(
            "<option value=\"%02d\" %s>%s</option>\n",
            $i,
            ($i == $cmonth ? "selected" : ""),
            $month_name[$i - 1]);
    }
    
    $Skinner->registerVariable("year_option_list", $year_list);
    $Skinner->registerVariable("month_option_list", $month_list);
    $Skinner->registerVariable("day_option_list", $day_list);
    $Skinner->registerVariable("lbl_ok", $labels["LBL_OK"]);
    
    $content=$Skinner->doSubstitution_FAST();


?>